#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
#include <string.h>

int main01(int argc, char const *argv[]){
        BiTNode t1, t2, t3, t4, t5;

        memset(&t1, 0, sizeof(BiTNode));
        memset(&t2, 0, sizeof(BiTNode));
        memset(&t3, 0, sizeof(BiTNode));
        memset(&t4, 0, sizeof(BiTNode));
        memset(&t5, 0, sizeof(BiTNode));

        t1.data = 1;
        t2.data = 2;
        t3.data = 3;
        t4.data = 4;
        t5.data = 5;

        //建立关系
        t1.lchild = &t2;
        t1.rchild = &t3;
        t2.lchild = &t4;
        t3.lchild = &t5;

        //树的遍历
        printf("先序遍历: ");
        DLR(&t1);
        printf("\n");

        printf("中序遍历: ");
        LDR(&t1);
        printf("\n");

        printf("后序遍历: ");
        LRD(&t1);
        printf("\n");

        printf("二叉树的叶子结点个数: %d\n", countLeafNum(&t1));
        printf("二叉树的高度: %d\n", depth(&t1));

        //拷贝一个树
        {
                BiTree tree = copyTree(&t1);
                printf("先序遍历拷贝后的一个树: ");
                DLR(tree);
                printf("\n");
        }

        printf("中序非递归遍历: ");
        LDR_NonRecursive(&t1);
        printf("\n");

        return 0;
}

int main02(int argc, char const *argv[])
{
        BiTNode * p1, *p2, *p3, *p4, *p5;

        p1 = (BiTNode *)malloc(sizeof(BiTNode));
        p2 = (BiTNode *)malloc(sizeof(BiTNode));
        p3 = (BiTNode *)malloc(sizeof(BiTNode));
        p4 = (BiTNode *)malloc(sizeof(BiTNode));
        p5 = (BiTNode *)malloc(sizeof(BiTNode));

        p1->data = 1;
        p2->data = 2;
        p3->data = 3;
        p4->data = 4;
        p5->data = 5;

        //建立关系
        p1->lchild = p2;
        p1->rchild = p3;
        p2->lchild = p4;
        p2->rchild = p5;

        //树的遍历

        return 0;
}

int main03(int argc, char const *argv[])
{
        BPTree tree;

        //根结点
        tree.nodes[0].parentPosition = 1000;

        //B
        tree.nodes[1].parentPosition = 0;
        tree.nodes[1].data='B';
        tree.nodes[1].LRTag = 1;

        //C
        tree.nodes[2].parentPosition = 0;
        tree.nodes[2].data='C';
        tree.nodes[2].LRTag = 2;

        return 0;
}

//#号法创建树
int main(int argc, char const *argv[])
{
        BiTree tree = NULL;
        tree =  createBTree();

        DLR(tree);
        printf("\n");

        BiTree_Free(tree);
        return 0;
}
